<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue</title>
    <script type="text/javascript" src="../../js/vue.js"></script>

</head>
<body>
    <div id="root">
        <input type="text" placeholder="输入姓名" v-model="keyWord">
         <!-- 遍历数组 -->
         <ul>
            <li v-for= "(p,index) in filterPersons" :key="p.id">
                {{p.name}} - {{p.age}} - {{index}} 
                <input type="text">
            </li>
        </ul>
        <hr>
    </div>

    <script type="text/javascript">
        Vue.config.performance = false;
        const vm = new Vue({
            el:'#root',
            data() {
                return {
                    persons:[
                        {id:'001',name:"张三",age:12},
                        {id:'002',name:"李四",age:18},
                        {id:'003',name:"张飞",age:20},
                        {id:'004',name:"赵四",age:20},
                        {id:'005',name:"流水",age:20},
                    ],
                    keyWord:'',
                    //filterPersons:[],
                };
            },
            // watch实现
            /* watch:{
                keyWord:{
                    immediate:true,
                    handler(newValue){
                        console.log(newValue)
                        this.filterPersons = this.persons.filter((p)=>{
                            return p.name.indexOf(newValue) != -1
                        })
                    }
                }
               
            } */
            // computer 实现
            computed:{
                filterPersons(){
                    return this.persons.filter((p)=>{
                        return p.name.indexOf(this.keyWord) !== -1
                    })
                }
            }
        })

    </script>

</body>
</html>